﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;

namespace Pager
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //this.page1.pageSize = 4;
        }
        private int num;
        private DataSet ds;

        page p = new page();

        public void LoadData(object sender, EventArgs e)
        {
            this.page1.SetPageCtrl(page1.pageIndex, page1.pageSize, 29);
            string sql =
                string.Format(
                    "SELECT TOP {0}* \r\nFROM \r\n        (\r\n        SELECT ROW_NUMBER() OVER (ORDER BY 学号) AS RowNumber,* FROM [dbo].[Class122]\r\n        ) A\r\nWHERE RowNumber > {1}*({2}-1)",
                    page1.pageSize, page1.pageSize, page1.pageIndex);
            ds = SqlHelper.ExecuteDataSet(sql);
            gridControl1.DataSource = ds.Tables[0];
        }
        //private void page1_CurrentPageChange(object sender, EventArgs e)
        //{
        //    LoadData();
        //}
        private void Form1_Load(object sender, EventArgs e)
        {
            //ds=new DataSet();

            ////num = SqlHelper.ExecuteNonQuery("select count(*) from [dbo].[Class122]");
            ////string sql = string.Format("SELECT TOP {0}* \r\nFROM \r\n        (\r\n        SELECT ROW_NUMBER() OVER (ORDER BY 学号) AS RowNumber,* FROM [dbo].[Class122]\r\n        ) A\r\nWHERE RowNumber > {1}*({2}-1)", page1.pageSize, page1.pageSize, (29 + 4) / page1.pageSize);
            string sql = string.Format("SELECT TOP {0}* \r\nFROM \r\n        (\r\n        SELECT ROW_NUMBER() OVER (ORDER BY 学号) AS RowNumber,* FROM [dbo].[Class122]\r\n        ) A\r\nWHERE RowNumber > {1}*(1-1)", page1.pageSize, page1.pageSize);
            this.page1.SetPageCtrl(1, page1.pageSize, 29); ds = SqlHelper.ExecuteDataSet(sql);
            gridControl1.DataSource = ds.Tables[0];
            page1.CurrentPageChange += new EventHandler(LoadData);
        }
        //private void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        //{
        //    if (e.Info.IsRowIndicator && e.RowHandle >= 0)
        //    {
        //        e.Info.DisplayText = (e.RowHandle + 1).ToString();
        //    }
        //}
    }
}
